/*
 * @Author: 姚沈阳 11500793+yao-shenyang@user.noreply.gitee.com
 * @Date: 2023-11-02 11:34:39
 * @LastEditors: 姚沈阳 11500793+yao-shenyang@user.noreply.gitee.com
 * @LastEditTime: 2023-11-02 14:59:43
 * @FilePath: \实训二PC\vue-project\src\modules\train.ts
 * @Description: 
 * qq1908552310
 */
import { defineStore } from 'pinia'
import * as api from '@/api/index'
export const useOrdersStore = defineStore('train', {
    state: () => {
        return {
            list: [], //分页完的数据
            datalist: [], //完整的数据
            currentPage: 1,// 当前页码
            pageSize: 5, // 每页记录数
        };
    },
    // 也可以这样定义
    // state: () => ({ count: 0 })

    actions: {
        async getOrders() {
            let data = await api.getTicket('http://localhost:7001/v1/api/orders')
            console.log(data, "data")
            this.datalist = data.data.data
            this.createdPage(data.data.data)
        },
        createdPage(data: any) {
            // 计算当前页的数据
            const start = (this.currentPage - 1) * this.pageSize;
            const end = start + this.pageSize;
            this.list = data.slice(start, end)

        },
        setCurrentPage(page: number) {
            this.currentPage = page
            this.getOrders()
        },
        setPageSize(page: number) {
            this.pageSize = page
            this.getOrders()
        }
    },
})